//该文件用于创建Vuex最为核心的store

//引入vue
import Vue from "vue"

//引入Vuex
import Vuex from "vuex"

Vue.use(Vuex)

//actions用于响应组件的动作
const actions = {
    /* jia(context, value) {
        context.commit("JIA", value);
    },
    jian(context, value) {
        context.commit("JIAN", value);
    }, */
    jiaOdd(context, value) {
        if (context.state.sum % 2) {
            context.commit("JIA", value);
        }
    },
    jiaWait(context, value) {
        setTimeout(() => {
            context.commit("JIA", value);
        }, 500);
    },
}

//mutations用于操作数据(state)
const mutations = {
    JIA(state, value) {
        state.sum += value;
    },
    JIAN(state, value) {
        state.sum -= value;
    },
}

//state用于存储数据
const state = {
    sum: 0,
}

//创建store暴露store
export default new Vuex.Store({
    actions,
    mutations,
    state,
})


